package rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@SuppressWarnings("serial")
@Entity
@Table(name = "voznja")
@NamedQueries({
		@NamedQuery(name = "nezapoceteVoznje", query = "select v from Voznja v where v.brojOsoba <= :brojOsoba and v.masaPrtljaga <= :masaPrtljaga and v.zapreminaPrtljaga <= :zapreminaPrtljaga and v.odrediste is null and v.cena is null"),
		@NamedQuery(name = "zavrsenePutnikoveVoznje", query = "select v from Voznja v where v.putnik.id = :putnikId and v.odrediste is not null and v.cena is not null"),
		@NamedQuery(name = "zavrseneVozaceveVoznje", query = "select v from Voznja v where v.vozac.id = :vozacId and v.odrediste is not null and v.cena is not null") })
public class Voznja implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "va_id")
	private Integer id;

	@Column(name = "va_cena", nullable = true)
	private Float cena;

	@Column(name = "va_broj_osoba", nullable = false)
	private Byte brojOsoba;

	@Column(name = "va_zapremina_prtljaga", nullable = false)
	private Float zapreminaPrtljaga;

	@Column(name = "va_masa_prtljaga", nullable = false)
	private Float masaPrtljaga;

	@Embedded
	@AttributeOverrides({
			@AttributeOverride(name = "x", column = @Column(name = "va_a_x", nullable = false)),
			@AttributeOverride(name = "y", column = @Column(name = "va_a_y", nullable = false)),
			@AttributeOverride(name = "adresa", column = @Column(name = "va_a_adresa")) })
	private Tacka ishodiste;

	@Embedded
	@AttributeOverrides({
			@AttributeOverride(name = "x", column = @Column(name = "va_b_x")),
			@AttributeOverride(name = "y", column = @Column(name = "va_b_y")),
			@AttributeOverride(name = "adresa", column = @Column(name = "va_b_adresa")) })
	private Tacka odrediste;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "va_pu_putnik", referencedColumnName = "ko_id", nullable = false)
	private Putnik putnik;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "va_vo_vozac", referencedColumnName = "ko_id", nullable = true)
	private Vozac vozac;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "va_vz_vozilo", referencedColumnName = "vo_id", nullable = true)
	private Vozilo vozilo;

	public Voznja() {
		super();
	}

	public Float getCena() {
		return cena;
	}

	public void setCena(Float cena) {
		this.cena = cena;
	}

	public Byte getBrojOsoba() {
		return brojOsoba;
	}

	public void setBrojOsoba(Byte brojOsoba) {
		this.brojOsoba = brojOsoba;
	}

	public Float getZapreminaPrtljaga() {
		return zapreminaPrtljaga;
	}

	public void setZapreminaPrtljaga(Float zapreminaPrtljaga) {
		this.zapreminaPrtljaga = zapreminaPrtljaga;
	}

	public Float getMasaPrtljaga() {
		return masaPrtljaga;
	}

	public void setMasaPrtljaga(Float masaPrtljaga) {
		this.masaPrtljaga = masaPrtljaga;
	}

	public Tacka getIshodiste() {
		return ishodiste;
	}

	public void setIshodiste(Tacka ishodiste) {
		this.ishodiste = ishodiste;
	}

	public Tacka getOdrediste() {
		return odrediste;
	}

	public void setOdrediste(Tacka odrediste) {
		this.odrediste = odrediste;
	}

	public Putnik getPutnik() {
		return putnik;
	}

	public void setPutnik(Putnik putnik) {
		this.putnik = putnik;
	}

	public Vozac getVozac() {
		return vozac;
	}

	public void setVozac(Vozac vozac) {
		this.vozac = vozac;
	}

	public Vozilo getVozilo() {
		return vozilo;
	}

	public void setVozilo(Vozilo vozilo) {
		this.vozilo = vozilo;
	}

	public Integer getId() {
		return id;
	}

	@Override
	public String toString() {
		return "Voznja [id=" + id + ", cena=" + cena + ", brojOsoba="
				+ brojOsoba + ", zapreminaPrtljaga=" + zapreminaPrtljaga
				+ ", masaPrtljaga=" + masaPrtljaga + ", ishodiste=" + ishodiste
				+ ", odrediste=" + odrediste + ", putnik=" + putnik
				+ ", vozac=" + vozac + ", vozilo=" + vozilo + "]";
	}

}
